package cn.edu.ujn.c;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.ujn.m.User;

@Controller
public class UserController {
	@GetMapping("/login")
	public String toLogin() {
		return "login";
	}
	@PostMapping("/login")
	public String login(User user,HttpSession session,Model model) {
		if("liukun".equals(user.getUsername())) {
			session.setAttribute("USER_SESSION", user);
			return "main";
		}
		model.addAttribute("msg","登录失败，用户名或密码错误！");
		return "login";
		
	}
	@GetMapping("/main")
	public String toMain() {
		return "main";
	}
	@RequestMapping("/logout")
	public String logout(HttpSession session) {
		session.invalidate();
		return "login";
	}

}








